<?php
function cmd_dev($id, $_POST)
{
 if (isset($_POST['valeur']) && !empty($_POST['valeur']))
 {
  $sql = new db();
  time();
  $req = "UPDATE commande SET  Etat='v', Last_Mod=".time().", Montant='".$_POST['valeur']."' WHERE Id_Commande=".$id;
  $sql->query($req);
 }
 header("Location:".ABS_PATH.ROOT."?page=Usine/Commande");
}

function cmd_entr($id, $_POST)
{
 if (isset($_POST['entrepot']) && !empty($_POST['entrepot']))
 {
 $sql = new db();
 time();
 $req = "UPDATE commande SET Etat='p', Last_Mod=".time().", GLN_Entrepot='".$_POST['entrepot']."' WHERE Id_Commande=".$id;
 $sql->query($req);
 $req = "INSERT INTO preparation VALUES (NULL, NOW(), '0000-00-00', '0', '', '0000-00-00', '0000-00-00', '".$id."')";
 $sql->query($req);
 $req = "INSERT INTO proposition_affretement VALUES (NULL, NOW(), '".$_POST['cout']."', 'Strat', '".$id."', '0')";
 $sql->query($req);
 }
 header("Location:".ABS_PATH.ROOT."?page=Usine/Commande");
} 

function cmd_del($id)
{
   $sql = new db();
   $req = 'DELETE commande, ligne_commande FROM commande, ligne_commande WHERE commande.Id_Commande='.$id.' AND ligne_commande.Id_Commande='.$id;
   $sql->query($req);
   header("Location:".ABS_PATH.ROOT."?page=Usine/Commande");
}

function cmd_val($id)
{
	$sql = new db();
	$req = "UPDATE commande SET Etat='c', Last_Mod=".time()." WHERE Id_Commande=".$id;
	$sql->query($req);
    header("Location:".ABS_PATH.ROOT."?page=Usine/Commande");
}

function cmd_ref ($id)
{
	$sql = new db();
	$req = "UPDATE commande SET Etat='r', Last_Mod=".time()." WHERE Id_Commande=".$id;
	$sql->query($req);
    header("Location:".ABS_PATH.ROOT."?page=Usine/Commande");
}

if (isset($_GET['id']) && !empty($_GET['id']) && isset($_GET['action']) && !empty($_GET['action']))
{
 switch ($_GET['action'])
 {
  case 'Delete':
   cmd_del($_GET['id']);
   break;
  case 'Accepte':
   cmd_val($_GET['id']);
   break;
  case 'Refuse':
   cmd_ref($_GET['id']);
   break;
  case 'Devis':
   cmd_dev($_GET['id'], $_POST);
   break;
  case 'Entrepot':
   cmd_entr($_GET['id'], $_POST);
   break;
 }
}

 ?>
	
	